<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设施配置</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../../styles/common.css"/>
    <link rel="stylesheet" href="../../../styles/page.css"/>
</head>
<body>
<div class="dashboard-container" id="StatisticsTHTB-app">
    <div class="container">
        <div class="tableBar">
            <el-input
                    v-model="input"
                    placeholder="请输入设施名称"
                    style="width: 250px"
                    clearable
                    @keyup.enter.native="handleQuery"
            >
                <i
                        slot="prefix"
                        class="el-input__icon el-icon-search"
                        style="cursor: pointer"
                        @click="init"
                ></i>
            </el-input>
            <div class="tableLab">
                <el-button  type="primary" class="continue" @click="addClass('class')"> + 设备配置 </el-button>
            </div>
        </div>
        <el-table  :data="tableData"  stripe  class="tableBox" >

            <el-table-column  prop="relayId" label="本系统内设备id"  /></el-table-column>
            <el-table-column  prop="relayName" label="位置id"  /></el-table-column>
            <el-table-column  prop="benRelayId" label="设备id"  /></el-table-column>
            <el-table-column  prop="type" label="操作类型"  /></el-table-column>
            <el-table-column  prop="code" label="返回结果码"  /></el-table-column>
            <el-table-column  prop="date" label="创建时间"  /></el-table-column>

            <!--  <el-table-column label="操作" width="160" align="center">
                  <template slot-scope="scope">
                      <el-button type="text" size="small" class="blueBug" @click="editHandle(scope.row)">修改</el-button>
                      <el-button type="text" size="small" class="delBut non" @click="deleteHandle(scope.row.id)">停用</el-button>
                  </template>
              </el-table-column>-->
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                @size-change="handleSizeChange"
                :current-page.sync="page"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
    <el-dialog :title="classData.title" :visible.sync="classData.dialogVisible" width="30%" :before-close="handleClose">
        <el-form class="demo-form-inline" label-width="100px">
            <el-form-item label="设施名称：">
                <el-input v-model="classData.facilitiesName" placeholder="请输入设施名称" maxlength="14"/>
            </el-form-item>

            <el-form-item label="温度阈值下限：">
                <el-input v-model="classData.temperatureLow" placeholder="请输入温度阈值下限" />
            </el-form-item>

            <el-form-item label="温度阈值上限：">
                <el-input v-model="classData.temperatureHigh" placeholder="请输入温度阈值上限" />
            </el-form-item>

            <el-form-item label="湿度阈值下限：">
                <el-input v-model="classData.humidityLow" placeholder="请输入湿度阈值下限" />
            </el-form-item>

            <el-form-item label="湿度阈值上限：">
                <el-input v-model="classData.humidityHigh" placeholder="请输入湿度阈值上限" />
            </el-form-item>

            <el-form-item label="土壤酸碱度下限：">
                <el-input v-model="classData.phLow" placeholder="请输入土壤酸碱度下限" />
            </el-form-item>

            <el-form-item label="土壤酸碱度上限：">
                <el-input v-model="classData.phHigh" placeholder="请输入土壤酸碱度上限" />
            </el-form-item>

            <el-form-item label="土壤溶液盐度下限：">
                <el-input v-model="classData.ecLow" placeholder="请输入土壤溶液盐度下限" />
            </el-form-item>

            <el-form-item label="土壤溶液盐度上限：">
                <el-input v-model="classData.ecHigh" placeholder="请输入土壤溶液盐度上限" />
            </el-form-item>

            <el-form-item label="光照度：">
                <el-input v-model="classData.illuminanceDegree" placeholder="请输入光照度" />
            </el-form-item>

            <el-form-item label="虫情：">
                <el-input v-model="classData.entomopathyThreshold" placeholder="请输入虫情" />
            </el-form-item>



            </el-form-item>





        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="classData.dialogVisible = false">取 消</el-button>
        <el-button type="primary" size="medium" @click="submitForm()">确 定</el-button>
        <el-button
                v-if="action != 'edit'"
                type="primary"
                size="medium"
                class="continue"
                @click="submitForm('go')"
        > 保存并继续添加 </el-button>
      </span>
    </el-dialog>
</div>
<script src="../../../plugins/vue/vue.js"></script>
<script src="../../../plugins/element-ui/index.js"></script>
<script src="../../../plugins/axios/axios.min.js"></script>
<script src="../../../js/request.js"></script>
<script src="../../../api/sysRole.js"></script>
<script src="../../../api/relay.js"></script>
<script type="text/javascript">
    new Vue({
        el: '#StatisticsTHTB-app',
        data() {
            return {
                action: '',
                tableData: [],
                type: '',
                classData: {
                    'title': '添加设施分类',
                    'dialogVisible': false,
                    'id':'',
                    'facilitiesId':'',
                    'facilitiesName':'',
                    'temperatureLow':'',
                    'temperatureHigh':'',
                    'humidityLow':'',
                    'humidityHigh':'',
                    'phLow':'',
                    'phHigh':'',
                    'ecLow':'',
                    'ecHigh':'',
                    'illuminanceDegree':'',
                    'entomopathyThreshold':'',

                },
                companyNameList: [],
                companyNameList2: [],
                page: 1,
                pageSize: 5,
                counts:0,
                input:''
            }
        },
        methods: {
            async init() {
                const params = {
                    page: this.page,//当前页码
                    pageSize: this.pageSize,//每页大小
                    name: this.input ? this.input : undefined//企业名称
                };
                await getStatisticsRelayPage(params).then(res => {
                    console.log(res.data.records)
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records;
                        this.counts = res.data.total;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 添加
            addClass(st) {
                this.classData.title = '新增角色';
                this.action = 'add';
                this.classData.dialogVisible = true

            },

            selectCompanyNameList(){
                const params = {
                    page: 1,//当前页码
                    pageSize: 100//每页大小

                };
                getRolePage(params).then(res => {
                    console.log(res.data.records)
                    const resData=res.data.records
                    if (String(res.code) === '1') {
                        this.companyNameList=[]
                        for(var i=0;i <resData.length;i++){
                            this.companyNameList.push({"value":resData[i].id,"label":resData[i].name})
                        }
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },



            //修改
            editHandle(dat) {
                console.log(dat)
                //赋值
                this.classData.title = '修改设施';
                this.action = 'edit';
                this.classData.id = dat.id;
                this.classData.facilitiesName = dat.facilitiesName;
                this.classData.temperatureLow = dat.temperatureLow;
                this.classData.temperatureHigh = dat.temperatureHigh;
                this.classData.humidityLow = dat.humidityLow;
                this.classData.humidityHigh = dat.humidityHigh;
                this.classData.phLow = dat.phLow;
                this.classData.phHigh = dat.phHigh;
                this.classData.ecLow = dat.ecLow;
                this.classData.ecHigh = dat.ecHigh;
                this.classData.illuminanceDegree = dat.illuminanceDegree;
                this.classData.entomopathyThreshold = dat.entomopathyThreshold;



                this.classData.dialogVisible = true;//打开修改框
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },
            //删除
            deleteHandle(id) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    'confirmButtonText': '确定',
                    'cancelButtonText': '取消',
                    'type': 'warning'
                }).then(() => {
                    deleteStatisticsRelay(id).then(res => {
                        if (res.code === 1) {
                            this.$message.success('删除成功！');
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                })
            },
            //数据提交
            submitForm(st) {
                const classData = this.classData;

                if (this.action === 'add') {

                    addStatisticsTHTB(classData).then(res => {
                        if (res.code === 1) {
                            this.$message.success('添加成功！')
                            if (!st) {
                                this.classData.dialogVisible = false
                            } else {
                                this.classData = {};
                            }
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })

                } else if (this.action === 'edit') {
                    editStatisticsRelay(classData).then(res => {
                        if (res.code === 1) {
                            this.$message.success('修改成功！');
                            this.classData.dialogVisible = false;
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })

                } else {
                    this.$message.error('请输入名称')
                }
            },
            // 全部操作
            handleSelectionChange(val) {
                let checkArr = []
                val.forEach((n) => {
                    checkArr.push(n.id)
                })
                this.checkList = checkArr
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val
                this.init()
            }
        },
        created() {
            this.init()
        },

    })
</script>
</body>
</html>